Euphoria to Win INIfile manager

LAST MINUTE CASE FIXED:
sequence_to_string( {{0},{0}} ) WAS {,}; NOW IS CORRECT.
=======================================================================
=======================================================================

Adds to a basic Wolfgang Fritz's read/write routines for the INI file strings
management the flexible and complete ability to record numbers and Euphoria
objects of any complexity, with the default declared options returned on not
found. Very compact; no "machine-level exception"  errors; no need of '\\',
both in write and read, and manually in the external file too (the user
should not be involved by this problem).

Just a little compromise: for Euphoria a string like "?@A" is equal to the
sequence {63,64,65} and one of these two espressions could always be
reversed into the other; in these routines this can only happen if the
sequence contains *only bytes* into the range 32-255 (rare, but possible),
because in this case it is processed as a plain string. So, if you don't
want a parameters list {65, 66, 67} appear into the INI file in the string
format "ABC", if not any negative number, or not integer, or out of
alphabetic range (there are so many! ;) is in the list, simply add to
that list AN EMPTY SEQUENCE {} to be ignored on read, or (better?) {65, 66, 67, 0}; 
this way it will force to the sequence format, as well as a sequence 
like {345, 678} will not be returned as a single string "{345, 678}" :(
You can also reverse this as an option whenever you wish an ASCII string 
not to appear into a legible format, to avoid the user to interfere. 

This seems however more simple and selectable than any other distinctive 
and fixed solution, like to prepend complicating -for users too!- strings 
to every sequence. In 2/100 cases I had to add a 0 on save, 1/100 need 
to cut it from the end of the loaded sequence, and that's all.
A small price for the power of Euphoria! The program is smallest and should
work fine, but this matter is a true puzzle, so use it at your own risk.

I am here: a.admin{64}myway.it, or soon at www.hyphenator.com.
Antonio Alessi, 21/02/2006

The syntax is:

writeINI( "Section", "Key", any_data_in_any_possible_EUformat)

readINI( "Section", "Key", default_data_in_any_possible_EUformat)
i.e.

    readINI( "Section", "Key",  default_NUMBER_to_be_returned_if_nothing_is_found)

    readINI( "Section", "Key", "default_STRING_to_be_returned_if_nothing_is_found")

    readINI( "Section", "Key",

           { "default_SEQUENCE_to_be_returned",
                {"if", nothing,
                     {"is", "found"} }

                     )


The type of the default parameter will teach the routine on what to return,
then it must match the record. The Wolf's Read routine was changed so that
you are not obliged to declare every time the default value: simply can enter
what is needed to qualify the type of the expected variable: .1, or "" or {{}}
may be enough. This way I could set three main subroutines as:

--- ========
global function INI_value( object section, object ctrl)

    return readINI( section, ctrl, 0)
end function
--- ========
global function INI_strng( object section, object ctrl)

    return readINI( section, ctrl, "")
end function
--- ========
global function INI_seqnc( object section, object ctrl)

    return readINI( section, ctrl, {""})
end function
--- ========

that allow such a strict solution:

--- ========
global function getWebAddress( )

    return INI_strng( "Paths", "Web_Update")

end function
--- ========

The sequence_to_string( ) routine can be used for any other purpose alike;
e.g. save as a line into a file
     to be read by the S = get(fn) EU command 
     in this case you must set '\' = '\\' when needed,
     using the included dbl_slash( ) routine:
--- =========

puts( fn, dbl_slash( sequence_to_string( {unthinkable_Sequence} ))&10)

unthinkable_Sequence = get( fn)

--- =========
http://www.myway.it/EU/Eu2Win_INIfile.zip

21/02/2006  -- ver. 1.3

autoR_readINI( ) INI AUTO REPAIR FEATURE ADDED.
==============================================
In this routine, that could be preferred in many cases,
when no record or value is found, a message is given;
if a Default value is declared by the calling routine
the Section and/or Key are built [again] into the INI file 
and the Default value is assigned and written then.
The user can abort the program before changes are made.

An empty default value, passed either as "" or as {""},
avoids messages when seeking the INI file for getting
a list or a group of data spread on several rows.
At this time I could not test it outside the limits 
of my application, but it works fine there ;)

18/10/2006  -- ver. 1.4

Fixed a bug in writeINI( ), at my 1st write error..

{MB_OK} must be: MB_OK